package com.wen.cim.route.controller;

import com.wen.cim.common.enums.StatusEnum;
import com.wen.cim.common.res.BaseResponse;
import com.wen.cim.route.api.RouteApi;
import com.wen.cim.route.api.req.RegisterInfoReqVO;
import com.wen.cim.route.api.res.RegisterInfoResVO;
import com.wen.cim.route.service.AccountService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author 文洪武
 * @title: RouteController
 * @projectName cim-master
 * @description: TODO
 * @date 2021/11/2421:02
 */
@Controller
@RequestMapping("/")
public class RouteController implements RouteApi {

    private final static Logger LOGGER = LoggerFactory.getLogger(RouteController.class);

    @Autowired
    AccountService accountService;

    @PostMapping("registerAccount")
    @ResponseBody()
    @Override
    public BaseResponse<RegisterInfoResVO> registerAccount(@RequestBody RegisterInfoReqVO registerInfoReqVO) throws Exception {
        BaseResponse<RegisterInfoResVO> res = new BaseResponse<>();
        // 暂时使用随机值作为id，后续再增加修改id的接口
        long userId = System.currentTimeMillis();
        RegisterInfoResVO info = new RegisterInfoResVO(userId, registerInfoReqVO.getUserName());
        info = accountService.register(info);

        res.setDataBody(info);
        res.setCode(StatusEnum.SUCCESS.getCode());
        res.setMessage(StatusEnum.SUCCESS.getMessage());

        return res;
    }

}
